using Vwf.Web;

namespace Vwf.Web.Controls {
	public abstract class Control : Object {
		
		public string name;
		
		public string globalName { 
			get {
				return (mainControl == null ? "" : mainControl.globalName + "-") + name;
			}
		};
		
		public bool visible = true;
		
		public ControlList content = new ControlList();
		
		public ControlList items = new ControlList();
		
		// true - is active, false - isn't active, null - inherid from parent
		public bool? active = null;
		
		// return actual value of active
		public bool isActive() {
			if (active != null) return (!)active;
			if (parent != null) return parent.isActive();
			return true;
		}
		
		public Control? parent;
		
		public Control? mainControl;
		
		public abstract render(Writer writer);
		
		public void add(Control item) {
			content.add(item);
			if (parent == mainControl) {
				// 
				items.add(item);
			} else {
				mainControl.items.add(item);
			}
		}
		
		public Control findControl(string controlName) {
			if (parent == mainControl) {
				foreach(var item in items) {
					if (item.name == controlName) return item;
				}
			} else {
				mainControl.findControl(controlName);
			}
		}
	}
}
